package com.skiving.cloud.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.noear.solon.cache.redisson.RedissonBuilder;
import org.noear.solon.cache.redisson.RedissonCacheService;
import org.noear.solon.data.cache.CacheService;
import org.noear.solon.data.cache.impl.JsonSerializer;
import org.noear.solon.vault.annotation.VaultInject;
import org.redisson.api.RedissonClient;

import java.util.Properties;

//配置缓存服务
@Configuration
public class RedisConfiguration {

    @Bean
    public RedissonClient redisClient(@VaultInject("${redis.cache}") Properties properties) {
        return RedissonBuilder.build(properties);
    }

    @Bean(name = "cache", typed = true) //typed 表示可类型注入 //即默认
    public CacheService cache1(@Inject RedissonClient client){
        RedissonCacheService cache = new RedissonCacheService(client, "skiving", 3600);
        cache.enableMd5key(false);
        return cache.serializer(JsonSerializer.typedInstance);
    }

}
